﻿$imt(document).ready(function() { 
var id=/^#comment-/;
var at=/:$/;
$imt('#comments li p a').each(function() {
	if($imt(this).attr('href').match(id)&& $imt(this).text().match(at)) {
		$imt(this).addClass('tip-atreply');
	}
});
$imt('.tip-atreply').hover(function() {
	var target = this;
	var _commentId = $imt(this).attr('href');
 
	if($imt(_commentId).is('.comment')) {
		$imt('<li class="comment-tip"></li>').hide().html($imt(_commentId).html()).appendTo($imt('ol.comment-list'));
		$imt('ol.comment-list .comment-tip').css({
			left:Position.cumulativeOffset(target)[0] + $imt(target).width() + 10,
			top:Position.cumulativeOffset(target)[1] - 22
		}).fadeIn(400);
	} else {
		var id = _commentId.slice(9);
		$imt.ajax({
			type:         'GET'
			,url:         '?action=load_comment&id=' + id
			,cache:       false
			,dataType:    'html'
			,contentType: 'application/json; charset=utf-8'
 
			,beforeSend: function(){
				$imt('<li class="comment-tip"></li>').hide().html('<p class="ajax-loader msg"></p>').appendTo($imt('ol.comment-list'));
				$imt('ol.comment-list .comment-tip').block({ 
					message: '<img src="'+imt_mysite_url+'images/ajax-loader.gif" />正在拉取评论请稍候～', 
					fadeIn: 1000, 
					fadeOut: 1000, 
					css: {width: '350px', top: '10px',left: '', right: '10px', border: 'none',  padding: '5px',  backgroundColor: '#000000', '-webkit-border-radius': '10px', '-moz-border-radius': '10px', opacity: .6, color: '#fff',cursor:'wait' }  
				}); 
				
				$imt('ol.comment-list .comment-tip').css({
					left:Position.cumulativeOffset(target)[0] + $imt(target).width() + 10,
					top:Position.cumulativeOffset(target)[1] - 22
				}).fadeIn(400);
			}
 
			,success: function(data){
				$imt('ol.comment-list .comment-tip').block({ 
					message: '<img src="'+imt_mysite_url+'images/ajax-loader.gif" />拉取评论信息成功！', 
					fadeIn: 1500, 
					fadeOut: 1500, 
					timeout: 4000, 
					showOverlay: false, 
					centerY: false, 
					css: {width: '620px', top: '10px',left: '', right: '10px', border: 'none',  padding: '5px',  backgroundColor: '#000000', '-webkit-border-radius': '10px', '-moz-border-radius': '10px', opacity: .6, color: '#fff',cursor:'wait' } 
				}); 
				var addedComment = $imt(data);
				addedComment.hide().appendTo($imt('ol.comment-list'));
				$imt('ol.comment-list .comment-tip').html(addedComment.html());
			}
 
			,error: function(){
				$imt('ol.comment-list .comment-tip').block({ 
					message: '<img src="'+imt_mysite_url+'images/ajax-loader.gif" />拉取评论信息失败！', 
					fadeIn: 1500, 
					fadeOut: 1500, 
					timeout: 4000, 
					showOverlay: false, 
					centerY: false, 
					css: {width: '620px', top: '10px',left: '', right: '10px', border: 'none',  padding: '5px',  backgroundColor: '#000000', '-webkit-border-radius': '10px', '-moz-border-radius': '10px', opacity: .6, color: '#fff',cursor:'wait' } 
				}); 
				$imt('ol.comment-list .comment-tip').html('<p class="msg">拉取评论信息失败！</p>');
			}
		});
	}
}, function() {
	$imt('ol.comment-list .comment-tip').fadeOut(400, function(){
		$imt(this).remove();
	});
});
})